class User < ActiveRecord::Base
	def validate
    unless email && email =~ /(.+)@(.+)\.(.{3})/ 
    errors.add(:email, "is invalid. Please enter a valid email address.");
      
    end
    
  end
  
  
  def validate
    unless mobile && mobile =~ /\A[+-]?\d+\Z/
    errors.add(:mobile, "is invalid. Please enter a valid phone number without using international format.");
      
    end
    
  end
  
  validates_presence_of :user_name 
  validates_length_of :user_name, :in => 3..10
  validates_uniqueness_of :user_name
  
  validates_presence_of :password
  validates_length_of :password, :in => 5..8
  
  validates_presence_of :email
  
  validates_presence_of :mobile
  validates_length_of :mobile, :is => 10
  
  
  
  
  
  has_many :attendances
  
	has_many :events, :through => :attendances, :order => 'date'
  
  
end
